import Vue from 'vue'
import App from './App.vue'
import VueMeta from 'vue-meta'
import createStore from './store/index'
import element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import createRouter from './router/index'
import createAxios from './config/axios-config'
import locale from 'element-ui/lib/locale/lang/en' //这里面可以修改国际化
import {RouterLink} from './components/router-go/router-link'

// Export factory function
export default function createApp(ctx) {
  // 1. Create a router instance
  const router = createRouter(ctx)
  const store = createStore()
  const axios = createAxios(ctx, router)

  vueConfig(axios)

  // 2. Create root component option
  const app = {
    router,
    store,
    head: {...Vue.$metaInfo},
    render: h => h(App)
  }

  // 3. return
  return app
}

createApp.pluginRuntimeOptions = {
  cookie: { /* options */}
}

function vueConfig(axios) {
  Vue.config.productionTip = false
  Vue.use(VueMeta)
  Vue.use(element, {locale})
  //这里为了避免单例axios，直接创建新的axios实例，并将其注入在本次vue实例中，在vue中使用this.$get()即可
  Vue.prototype.$get = axios.get
  Vue.prototype.$del = axios.del
  Vue.prototype.$post = axios.post
  Vue.prototype.$put = axios.put

  Vue.prototype.$go = RouterLink //这里注入vue全局跳转，js方式

}
